#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int len=1e5+10;
ll T,n,m,l,v_lim;
int eye[len][2];
struct car{
    int d,v,a;
}arr[len];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    while(T--){
        cin>>n>>m>>l>>v_lim;
        int flag_a0=1,cnt=0,ope=0;
        for(int i=1;i<=n;i++){
            cin>>arr[i].d>>arr[i].v>>arr[i].a;
            if(arr[i].a!=0) flag_a0=0;
        }
        for(int i=1;i<=m;i++) cin>>eye[i][0];//stdin
        for(int i=1;i<=n;i++){
                int flag=1;
            if(arr[i].a>0){
                if(arr[i].v>=v_lim){
                    for(int j=m;j>=1;j--){
                        if(eye[j][0]<arr[i].d) break;
                        if(eye[j][1]==0){
                            eye[j][1]=1;
                            ope++;
                        }
                        if(flag){
                            flag=0;
                            cnt++;
                        }
                    }
                }
                else{
                    double x=(v_lim*v_lim-arr[i].v*arr[i].v)/2/arr[i].a+arr[i].d;
                    for(int j=m;j>=0;j--){
                        if(eye[j][0]<x) break;
                        if(eye[j][1]==0){
                            eye[j][1]=1;
                            ope++;
                        }
                        if(flag){
                            flag=0;
                            cnt++;
                        }
                    }
                }
            }
        }
        cout<<cnt<<' '<<m-ope<<'\n';
    }
    return 0;
}
